package com.itheima.day17_反射和类加载器.Test02;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Demo {
    public static void main(String[] args) throws ClassNotFoundException,IllegalAccessException, InstantiationException, NoSuchFieldException {
        HashMap<String, Object> map = new HashMap<>();
        map.put("id", "heima001");
        map.put("name", "张三");
        map.put("age", 23);
        map.put("birthday", "1999-09-09");

        Class c = Class.forName("com.itheima.day17_反射和类加载器.Test02.Student");
        Object obj = c.newInstance();
        Set<Map.Entry<String, Object>> entries = map.entrySet();
        for (Map.Entry<String, Object> entry : entries) {
            String key = entry.getKey();
            Field f = c.getDeclaredField(key);
            f.setAccessible(true);
            f.set(obj,entry.getValue());
        }
        System.out.println(obj);
    }
}
